//
//  SecViewController.m
//  悦享
//
//  Created by dllo on 16/3/17.
//  Copyright © 2016年 张洪国. All rights reserved.
//

#import "SecViewController.h"

@interface SecViewController ()<UIWebViewDelegate>

@property (nonatomic, retain) UIWebView *webView;/**<  网络视图 */
@property (nonatomic, retain) UIView *backView;/**<  背景的view */
@property (nonatomic, retain) UIActivityIndicatorView *activity;/**<  小菊花 */

@property (nonatomic, retain) UIButton *backButton;/**<  返回button */

@property (nonatomic, retain) UIButton *relesButton;/**<  reloadButton */
@property (nonatomic, retain) UIButton *gofButton;/**<  web 前进button */
@property (nonatomic, retain) UIButton *gobButton;/**<  web 后退button */
@end

@implementation SecViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self createWebView];
    
    [self createBackView];
    [_activity startAnimating];

    
    [self createBackButton];
    
}

- (void)createBackButton{
    
    UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(0, SREEN_HEIGHT - 60, SREEN_WIDTH, 60)];
    view1.backgroundColor = [UIColor colorWithRed:0.13 green:0.13 blue:0.13 alpha:1];
    [self.view addSubview:view1];
    
    self.backButton = [UIButton buttonWithType:UIButtonTypeCustom];
    _backButton.frame = CGRectMake(10, 10, 40, 40);
    [_backButton setImage:[UIImage imageNamed:@"iconfont-zuojiantou.png"] forState:UIControlStateNormal];
    [_backButton addTarget:self action:@selector(backButton:) forControlEvents:UIControlEventTouchUpInside];
    [view1 addSubview:_backButton];
    
    self.relesButton = [UIButton buttonWithType:UIButtonTypeCustom];
    _relesButton.frame = CGRectMake(SREEN_WIDTH - 50, 10, 40, 40);
    [_relesButton setImage:[UIImage imageNamed:@"iconfont-shuaxin.png"] forState:UIControlStateNormal];
    [_relesButton addTarget:self action:@selector(relButton:) forControlEvents:UIControlEventTouchUpInside];
    
    [view1 addSubview:_relesButton];
    
    self.gobButton = [UIButton buttonWithType:UIButtonTypeCustom];
    _gobButton.frame = CGRectMake(SREEN_WIDTH - 150, 10, 40, 40);
    [_gobButton setImage:[UIImage imageNamed:@"iconfont-houtui.png"] forState:UIControlStateNormal];
    [_gobButton addTarget:self action:@selector(gobButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    
    [view1 addSubview:_gobButton];
    
    
    self.gofButton = [UIButton buttonWithType:UIButtonTypeCustom];
    _gofButton.frame = CGRectMake(SREEN_WIDTH - 100, 10, 40, 40);
    [_gofButton setImage:[UIImage imageNamed:@"iconfont-qianjin.png"] forState:UIControlStateNormal];
    [_gofButton addTarget:self action:@selector(gofButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    
    [view1 addSubview:_gofButton];
    
}
///返回
- (void)backButton:(UIButton *)button{
      [self dismissViewControllerAnimated:YES completion:^{
          
      }];
}
///刷新
- (void)relButton:(UIButton *)button{
    [_webView reload];
}
///后退
- (void)gobButtonAction:(UIButton *)button{
    [_webView goBack];
}
///前进
- (void)gofButtonAction:(UIButton *)button{
    [_webView goForward];
}
- (void)createBackView{
    
    self.backView = [[UIView alloc] initWithFrame:self.view.bounds];
    _backView.backgroundColor = [UIColor blackColor];
    _backView.alpha = 0.6;
    
    [self.view addSubview:_backView];
    
    self.activity = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
    _activity.frame = CGRectMake(0, 0, 50, 50);
    _activity.center = _backView.center;
    [_backView addSubview:_activity];
    
}

- (void)createWebView{
    
    self.webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, -35, SREEN_WIDTH, SREEN_HEIGHT-40)];
    [_webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:self.url]]];
    _webView.delegate = self;
    [self.view addSubview:_webView];
    
}
#pragma mark-webView代理方法
- (void)webViewDidStartLoad:(UIWebView *)webView{
    
}
- (void)webViewDidFinishLoad:(UIWebView *)webView{
    [_activity stopAnimating];
    [_backView removeFromSuperview];
    
    
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
